# This Python file uses the following encoding: utf-8
import sys
from PySide2.QtWidgets import QApplication,QMainWindow,QMessageBox
import mainwindow
from PySide2 import QtWidgets,QtCore, QtGui
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
import os
from pathlib import Path
from CatchObj import CatchObj

class Test(QMainWindow,mainwindow.Ui_MainWindow):
    def __init__(self):
        super(Test, self).__init__()
        self.setupUi(self)

    # 添加中文的确认退出提示框1
    def closeEvent(self, event):
        # 创建一个消息盒子（提示框）
        quitMsgBox = QMessageBox()
        # 设置提示框的标题
        quitMsgBox.setWindowTitle('确认提示')
        # 设置提示框的内容
        quitMsgBox.setText('你确认退出吗？')
        # 设置按钮标准，一个yes一个no
        quitMsgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
        # 获取两个按钮并且修改显示文本
        buttonY = quitMsgBox.button(QMessageBox.Yes)
        buttonY.setText('确定')
        buttonN = quitMsgBox.button(QMessageBox.No)
        buttonN.setText('取消')
        quitMsgBox.exec_()
        # 判断返回值，如果点击的是Yes按钮，我们就关闭组件和应用，否则就忽略关闭事件
        if quitMsgBox.clickedButton() == buttonY:
            event.accept()
        else:
            event.ignore()


def loadUi(uiFileName):
    loader = QUiLoader()
    path = os.fspath(Path(__file__).resolve().parent / uiFileName)
    ui_file = QFile(path)
    ui_file.open(QFile.ReadOnly)
    subUi = loader.load(ui_file)
    ui_file.close()
    return subUi

if __name__ == "__main__":
    app = QApplication([])
#    mainWindow = QMainWindow()
    mainUi = Test()
    mainUi.setupUi(mainUi)

    catchUi = loadUi("catch.ui")
    serverUi = loadUi("server.ui")
    dbUi = loadUi("db.ui")
    #加载自己的界面
    catchObj = CatchObj(catchUi)

    mainUi.mainTabWidget.addTab(catchObj.ui,"抓取配置")
    mainUi.mainTabWidget.addTab(serverUi,"服务配置")
    mainUi.mainTabWidget.addTab(dbUi,"数据库配置")
    mainUi.mainTabWidget.addTab(None,"服务配置")





    mainUi.show()
    sys.exit(app.exec_())
